#!/bin/bash
#     Script which should help users install / tweak some stuff immediately 
#     after installing Ubuntu 10.04 Lucid Lynx 32bit and 64bit.
#
#                           version 0.4.9.4
#
#     The script comes with no warranty. The author is not responsible if
#     your system breaks.
#
##   
##    Copyright (C) 2010 Alin Andrei, http://www.webupd8.org
##
##    This program is free software: you can redistribute it and/or modify
##    it under the terms of the GNU General Public License as published by
##    the Free Software Foundation, either version 3 of the License, or
##    (at your option) any later version.
##
##    This program is distributed in the hope that it will be useful,
##    but WITHOUT ANY WARRANTY; without even the implied warranty of
##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##    GNU General Public License for more details.
##
##    You should have received a copy of the GNU General Public License
##    along with this program. If not, see <http://www.gnu.org/licenses/>.
#####################
#Credits: 
#andreineculau.com for original Pidgin icons, Mongi Gazelle for the sharp fonts script.
#based on the idea of: http://czytelnia.ubuntu.pl/index.php/2009/11/03/skrypt-ulatwiajacy-konfiguracje-ubuntu-9-10-karmic-koala/, but Ubuntu Start is a completely re-written script with lots of new features.
#####################
#Options explainations:
#Move window buttons to the right (karmic style) - will move the metacity window buttons to the right side, in the following order: Minimize, Maximize, Close
#Change Update Manager behavior to the one in Jaunty - Ubuntu 9.04 (and newer) introduced a change to the handling of package updates, launching update-manager directly instead of displaying a notification icon in the GNOME panel. Users will still be notified of security updates on a daily basis, but for updates that are not security-related, users will only be prompted once a week. This tweak makes the update-manager not pop-up, but always show the updates in the notification area.
#Remove mounted drive icons from desktop - removes ntfs and usb drives from the desktop; usually when mounting a drive it shows up on the desktop
#Disable the GDM login sound - all the sounds in Ubuntu can be turned off from a GUI except this one. This is the sound produced when the GDM login screen loads.
#Enable the icons in menus and buttons - the icons in menus and buttons were removed in Gnome 2.28 (starting with Ubuntu Karmic). However, up until Lucid, users were able to enable these from the Appearence dialog preferences. This is no longer possible so use this tweak instead.
#Disable the GDM login user list - in Lucid, the users are displayed in the GDM login screen (which IMO is a security concern). This fix will make no user show up in this list, and for logging in you must enter your username and password manually.
#Change Gnome Calendar first day of the week from Sunday to Monday tweak - Gnome Calendar comes with Sunday as the first day of the week if the user has en_US language and there's no GUI way to change this. This tweak fixes this for non-US citizens using en_US Ubuntu (only use for en_US Ubuntu!)
#Remove the ubuntu-docs package (frees up 252MB): removed the ubuntu-docs package to free up 252 MB of disk space.
#Install and configure sharp fonts: info about this feature, here: http://www.webupd8.org/2009/09/ubuntu-debian-script-to-install-sharp.html
#Fix 'apt-get update' delay for Google Chrome repository - when downloading Google Chrome .deb, it automatically adds the Google Chrome repository. This repository has a known issue which cause "sudo apt-get update" to take a very long time to complete. This tweak fixes this issue.
#Add additional repositories (GetDeb, Medibuntu etc.) - Adds the following repositories: Getdeb, Medibuntu, Ubuntu universe and multiverse and Lucid partner.
########
#The second dialog - install packages.



TRUETYPEPATH="/usr/share/fonts/truetype/"
ROOT_UID=0

#uncomment the following line if the script doesn't run with your language
#export LC_CTYPE="en_US.UTF-8"


#running gconf-tool2 with "sudo" fails to set the options for the current user so this tweak makes it possible to run sudo for gconf-tool2 and change the setting for the current user, not the root user
ON_USER=$(echo ~ | awk -F'/' '{ print $1 $2 $3 }' | sed 's/home//g')
export $(grep -v "^#" ~/.dbus/session-bus/`cat /var/lib/dbus/machine-id`-0)
if sudo -u $ON_USER test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
       eval `sudo -u $ON_USER dbus-launch --sh-syntax --exit-with-session`
fi
#turn these on for debugging:
#echo $ON_USER
#echo $DBUS_SESSION
#echo $DBUS_SESSION_BUS_ADDRESS
#echo $DBUS_SESSION_BUS_WINDOWID
#echo $DBUS_SESSION_BUS_PID

##start language implementation
langselect=`/usr/bin/zenity --title="Please select a language" --width=300 --height=200 \
                            --text="Select:" \
                            --list --column="Selected" --column="Language" \
                            --radiolist TRUE English FALSE Arabic FALSE Asturian FALSE "Bahasa Indonesia" FALSE Catalan FALSE "Simplified Chinese" False "Traditional Chinese" FALSE Czech False Danish FALSE Dutch FALSE Estonian FALSE French FALSE Galician FALSE German FALSE Italian FALSE Japanese FALSE Korean FALSE Malaysian FALSE Polish FALSE "Portuguese (BR)" FALSE "Portuguese (PT)" FALSE Romanian FALSE Slovak FALSE Slovenian FALSE Spanish FALSE Swedish FALSE Turkish FALSE Urdu FALSE Vietnamese`


if [ $? -eq 0 ];
then
        IFS="|"
        for langSselect in $langselect
        do
               if [ "$langSselect" = "English" ];
                     then 
                     YOURLANG="languages/en.pot"
             elif [ "$langSselect" = "Arabic" ];
                     then
                     YOURLANG="languages/ar.pot"                     
             elif [ "$langSselect" = "Bahasa Indonesia" ];
                     then
                     YOURLANG="languages/id.pot"
             elif [ "$langSselect" = "Asturian" ];
                     then
                     YOURLANG="languages/ast.pot"                     
             elif [ "$langSselect" = "Czech" ];
                     then
                     YOURLANG="languages/cz.pot"                     
              elif [ "$langSselect" = "Catalan" ];
                     then
                     YOURLANG="languages/cat.pot"  
              elif [ "$langSselect" = "Simplified Chinese" ];
                     then
                     YOURLANG="languages/zh_CN.pot"     
              elif [ "$langSselect" = "Traditional Chinese" ];
                     then
                     YOURLANG="languages/zh_TW.pot"      
              elif [ "$langSselect" = "Danish" ];
                     then
                     YOURLANG="languages/da.pot"
               elif [ "$langSselect" = "Dutch" ];
                     then
                     YOURLANG="languages/nl.pot"     
               elif [ "$langSselect" = "Estonian" ];
                     then
                     YOURLANG="languages/et.pot"                                         
               elif [ "$langSselect" = "French" ];
                     then
                     YOURLANG="languages/fr.pot"    
               elif [ "$langSselect" = "Galician" ];
                     then
                     YOURLANG="languages/ga.pot"                         
               elif [ "$langSselect" = "German" ];
                     then
                     YOURLANG="languages/de.pot"   
               elif [ "$langSselect" = "Italian" ];
                     then
                     YOURLANG="languages/it.pot"    
              elif [ "$langSselect" = "Japanese" ];
                     then
                     YOURLANG="languages/jp.pot"   
              elif [ "$langSselect" = "Korean" ];
                     then
                     YOURLANG="languages/ko.pot"                           
              elif [ "$langSselect" = "Malaysian" ];
                     then
                     YOURLANG="languages/ms.pot"                                             
               elif [ "$langSselect" = "Polish" ];
                     then
                     YOURLANG="languages/pl.pot"   
              elif [ "$langSselect" = "Portuguese (BR)" ];
                     then
                     YOURLANG="languages/pt_BR.pot"                       
               elif [ "$langSselect" = "Portuguese (PT)" ];
                     then
                     YOURLANG="languages/pt_PT.pot"                                                             
               elif [ "$langSselect" = "Slovak" ];
                     then
                     YOURLANG="languages/sk.pot"    
               elif [ "$langSselect" = "Slovenian" ];
                     then
                     YOURLANG="languages/sl.pot"                        
              elif [ "$langSselect" = "Romanian" ];
                     then
                     YOURLANG="languages/ro.pot"                                                                            
               elif [ "$langSselect" = "Spanish" ];
                     then
                     YOURLANG="languages/es.pot"
               elif [ "$langSselect" = "Swedish" ];
                     then
                     YOURLANG="languages/sv.pot"                     
               elif [ "$langSselect" = "Turkish" ];
                     then
                     YOURLANG="languages/tr.pot"   
               elif [ "$langSselect" = "Urdu" ];
                     then
                     YOURLANG="languages/ur.pot"                          
               elif [ "$langSselect" = "Vietnamese" ];
                     then
                     YOURLANG="languages/vi.pot"                                          
               fi
        done
        IFS=""
else
        echo cancel selected
        exit
fi

LANGFILE=$(cat $YOURLANG)

n=1
while read curline; do
export WORD$n="$curline" #> /dev/null 2>&1
let n=n+1
done < $YOURLANG

#debugging
#echo "$WORD1"
#echo "$WORD2"
#echo "$WORD3"
##end language implementation

#check if the user is running Lucid 32 or 64bit
if [ "lucid" = `lsb_release -cs` ]; then
   if [ "i686" = `uname -m` ]; then
       echo using Ubuntu 10.04 Lucid Lynx - ok
       arch=i386
   elif [ "x86_64" = `uname -m` ]; then
       echo using Ubuntu 10.04 Lucid Lynx - ok
       arch=amd64
   else
       /usr/bin/zenity --warning --title="$WORD1" --text="$WORD2"
       echo You are not using Ubuntu 10.04 Lucid Lynx 32bit or 64bit, exiting
       exit
   fi
else
       /usr/bin/zenity --warning --title="$WORD1" --text="$WORD3"
       echo You are not using Ubuntu 10.04 Lucid Lynx, exiting
       exit
fi

# needs to be run with sudo
if [ "$UID" -ne "$ROOT_UID" ];
   then
   /usr/bin/zenity --warning --title="$WORD1" --text="$WORD4"
   echo "Exiting ... please run the script with sudo (eg: sudo ./ubuntu-10.04-script)"
   exit
fi

# check if there are applications running which can interfere with the script
sleep 1
for lock in synaptic update-manager software-center apt-get dpkg aptitude
do
if ps -U root -u root u | grep $lock | grep -v grep > /dev/null;
       then 
       echo "Installation won't work. Please close $lock first then try again.";
       /usr/bin/zenity --warning --title="$WORD1" --text="$WORD5 $lock $WORD6"
       exit
fi
done

#check if the user has an active internet connection
function testConnection() 
{
testconnection=`wget --tries=3 --timeout=15 www.google.com -O /tmp/testinternet &>/dev/null 2>&1`
if [ $? != 0 ]; then
echo  "You are not connected to the Internet. Please check your Internet connection and try again."
/usr/bin/zenity --info --text="$WORD7"
else
echo Internet connection - ok
fi
}


#gui 1
choicess=`/usr/bin/zenity --title="$WORD8" --width=500 --height=450 \
                          --text="$WORD9" \
                         --list --column="$WORD10" --column="$WORD11" \
                         --checklist FALSE "$WORD12" FALSE "$WORD13" FALSE "$WORD14" FALSE "$WORD15" FALSE "$WORD16" FALSE "$WORD17" FALSE "$WORD18" FALSE "$WORD19" FALSE "$WORD20" FALSE "$WORD21" FALSE "$WORD22" FALSE "$WORD23" FALSE "$WORD24" FALSE "$WORD25" FALSE "$WORD26" FALSE "$WORD27" FALSE "$WORD28" FALSE "$WORD29" TRUE "$WORD30" FALSE "$WORD31" FALSE "$WORD32" FALSE "$WORD33" TRUE "$WORD34"`


if [ $? -eq 0 ];
then
        IFS="|"
        for choicee in $choicess
        do
               if [ "$choicee" = "$WORD12" ];
                     then 
                     sudo -u $ON_USER "DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS gconftool-2 --type string --set /apps/metacity/general/button_layout ":minimize,maximize,close"
               elif [ "$choicee" = "$WORD13" ];
                     then
                     sudo -u $ON_USER "DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS gconftool-2 --type string --set /apps/metacity/general/button_layout "close,minimize,maximize:"    
               elif [ "$choicee" = "$WORD14" ];
                     then
                     sudo -u $ON_USER "DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS gconftool -s --type bool /apps/update-notifier/auto_launch false
               elif [ "$choicee" = "$WORD15" ];
                     then
                     sudo -u $ON_USER "DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS gconftool -s --type bool /apps/update-notifier/auto_launch true                     
              elif [ "$choicee" = "$WORD16" ];
                     then
                     sudo -u $ON_USER "DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS gconftool -s --type bool /apps/nautilus/desktop/volumes_visible false
              elif [ "$choicee" = "$WORD17" ];
                     then
                     sudo -u $ON_USER "DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS gconftool -s --type bool /apps/nautilus/desktop/volumes_visible true                     
               elif [ "$choicee" = "$WORD18" ];
                     then
                     sudo -u gdm gconftool-2 --set /desktop/gnome/sound/event_sounds --type bool false
                     sudo -u $ON_USER "DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS gconftool-2 --set /desktop/gnome/sound/event_sounds --type bool false
               elif [ "$choicee" = "$WORD19" ];
                     then
                     sudo -u gdm gconftool-2 --set /desktop/gnome/sound/event_sounds --type bool true
                     sudo -u $ON_USER "DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS gconftool-2 --set /desktop/gnome/sound/event_sounds --type bool true                   
              elif [ "$choicee" = "$WORD20" ];
                     then
                     sudo -u $ON_USER "DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS gconftool-2 --set /desktop/gnome/interface/buttons_have_icons --type bool true
                     sudo -u $ON_USER "DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS gconftool-2 --set /desktop/gnome/interface/menus_have_icons --type bool true
              elif [ "$choicee" = "$WORD21" ];
                     then
                     sudo -u $ON_USER "DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS gconftool-2 --set /desktop/gnome/interface/buttons_have_icons --type bool false
                     sudo -u $ON_USER "DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS gconftool-2 --set /desktop/gnome/interface/menus_have_icons --type bool false                     
              elif [ "$choicee" = "$WORD22" ];
                     then
                     sudo -u gdm gconftool-2 --set --type boolean /apps/gdm/simple-greeter/disable_user_list true
             elif [ "$choicee" = "$WORD23" ];
                     then
                     sudo -u gdm gconftool-2 --set --type boolean /apps/gdm/simple-greeter/disable_user_list false
              elif [ "$choicee" = "$WORD24" ];
                     then
                     timee=$(cat /etc/default/locale | grep "LC_TIME")
                     if [ ! $timee ]; then
                     timeee=$(/usr/bin/zenity --entry --title="$WORD35" --text="$WORD36")
                        if [ $timeee ]; then
                            echo LC_TIME=\"$timeee.UTF-8\" | sudo tee -a /etc/default/locale > /dev/null
                        else
                            echo LC_TIME=\"en_GB.UTF-8\" | sudo tee -a /etc/default/locale > /dev/null
                        fi    
                     else
                     echo "You already have custom values for LC_TIME, skipping this tweak"
                     fi
              elif [ "$choicee" = "$WORD25" ];
                     then
                     sudo rm /etc/default/locale_back > /dev/null 2>&1; sudo cp /etc/default/locale /etc/default/locale_back; cat /etc/default/locale_back | sudo sed -e '/^LC_TIME.*/d' > /etc/default/locale; sudo rm /etc/default/locale_back > /dev/null 2>&1;                
              elif [ "$choicee" = "$WORD26" ];
                     then
                     sudo apt-get remove -y --force-yes ubuntu-docs
              elif [ "$choicee" = "$WORD27" ];
                     then
                     sudo apt-get -y --force-yes install ubuntu-docs                     
              elif [ "$choicee" = "$WORD28" ];
                     then 
                     testConnection
                     /usr/bin/zenity --info --text="$WORD37"
                     cd /tmp
                     echo "Installing Sharpfonts. This may take a few minutes depending on connection speed..."
                     # download and install the cabextract tool
                     echo "Installing the cabextract tool..."
                     sudo apt-get install -y --force-yes cabextract
                     # Download all needed fonts
                     wget http://sharpfonts.com/fonts/andale32.exe
                     wget http://sharpfonts.com/fonts/arial32.exe
                     wget http://sharpfonts.com/fonts/arialb32.exe
                     wget http://sharpfonts.com/fonts/comic32.exe
                     wget http://sharpfonts.com/fonts/courie32.exe
                     wget http://sharpfonts.com/fonts/georgi32.exe
                     wget http://sharpfonts.com/fonts/impact32.exe
                     wget http://sharpfonts.com/fonts/tahoma32.exe
                     wget http://sharpfonts.com/fonts/times32.exe
                     wget http://sharpfonts.com/fonts/trebuc32.exe
                     wget http://sharpfonts.com/fonts/verdan32.exe
                     wget http://sharpfonts.com/fonts/webdin32.exe
                     # create the needed directory if it is not existing
                     if [ ! -d $TRUETYPEPATH ]; then
                     mkdir -p $TRUETYPEPATH
                     fi
                     # Extract all fonts to the truetype directory
                     cabextract -d /usr/share/fonts/truetype/ andale32.exe arial32.exe arialb32.exe comic32.exe courie32.exe georgi32.exe impact32.exe tahoma32.exe times32.exe trebuc32.exe verdan32.exe webdin32.exe
                     # Download the xml files and extract the configuration files into /etc/fonts/
                     wget http://sharpfonts.com/fontconfig.tbz
                     tar xvjpf fontconfig.tbz -C /etc/fonts/
                     rm -r /tmp/*.exe > /dev/null 2>&1;
                     rm /tmp/fontconfig.tbz > /dev/null 2>&1;
                     #Firefox sharp fonts
                     touch ~/.fonts.conf
                     echo "<?xml version=\"1.0\"?><!DOCTYPE fontconfig SYSTEM \"fonts.dtd\">" | tee  ~/.fonts.conf
		     echo "<fontconfig>" | tee -a ~/.fonts.conf
		     echo "<match target=\"font\" >" | tee -a ~/.fonts.conf
		     echo "<edit mode=\"assign\" name=\"rgba\" >" | tee -a ~/.fonts.conf
		     echo "<const>rgb</const>" | tee -a ~/.fonts.conf
	    	     echo "</edit>" | tee -a ~/.fonts.conf
		     echo "</match>" | tee -a ~/.fonts.conf
		     echo "<match target=\"font\" >" | tee -a ~/.fonts.conf
		     echo "<edit mode=\"assign\" name=\"hinting\" >" | tee -a ~/.fonts.conf
		     echo "<bool>true</bool>" | tee -a ~/.fonts.conf
		     echo "</edit>" | tee -a ~/.fonts.conf
		     echo "</match>" | tee -a ~/.fonts.conf
		     echo "<match target=\"font\" >" | tee -a ~/.fonts.conf
		     echo "<edit mode=\"assign\" name=\"hintstyle\" >" | tee -a ~/.fonts.conf
		     echo "<const>hintfull</const>" | tee -a ~/.fonts.conf
		     echo "</edit>" | tee -a ~/.fonts.conf
		     echo "</match>" | tee -a ~/.fonts.conf
		     echo "<match target=\"font\" >" | tee -a ~/.fonts.conf
		     echo "<edit mode=\"assign\" name=\"antialias\" >" | tee -a ~/.fonts.conf
		     echo "<bool>true</bool>" | tee -a ~/.fonts.conf
		     echo "</edit>" | tee -a ~/.fonts.conf
		     echo "</match>" | tee -a ~/.fonts.conf
		     echo "</fontconfig>" | tee -a ~/.fonts.conf
		     chown $ON_USER ~/.fonts.conf
                   
                     echo "Sharp fonts installation finished... Please remember to logout and login again"
                     
              elif [ "$choicee" = "$WORD29" ];
                     then
                     rm /etc/fonts/alias.conf /etc/fonts/local.conf /etc/fonts/misc.conf /etc/fonts/msfonts-rules.conf ~/.fonts.conf > /dev/null 2>&1;
              elif [ "$choicee" = "$WORD30" ];
                     then
                     echo "Acquire::http::Pipeline-Depth \"0\";" | sudo tee -a /etc/apt/apt.conf.d/90localsettings > /dev/null
              elif [ "$choicee" = "$WORD31" ];
                     then
                     sudo rm /etc/apt/apt.conf.d/90localsettings_back > /dev/null 2>&1; sudo cp /etc/apt/apt.conf.d/90localsettings /etc/apt/apt.conf.d/90localsettings_back; cat /etc/apt/apt.conf.d/90localsettings_back | sudo sed -e '/^Acquire::http::Pipeline-Depth.*/d' > /etc/apt/apt.conf.d/90localsettings; sudo rm /etc/apt/apt.conf.d/90localsettings_back > /dev/null 2>&1;
              elif [ "$choicee" = "$WORD32" ];
                     then
                         sudo apt-get -y --force-yes install ntfs-3g

				if [ $(cat /etc/fstab | grep '^[^#].*ntfs-3g' > /tmp/checkntfs-3g.txt; cat /tmp/checkntfs-3g.txt | wc -l) -gt 0 ];
				then
				    echo You already have ntfs-3g enabled
				else
					NTFSS=$(sudo blkid -c /dev/null -t TYPE=ntfs | cut -d ':' -f 1 > /tmp/checkntfs.txt)
					while read curline; do
					      echo $curline #debugging
					      dirr=$(echo $curline | cut -c 6- | sed -e 's/\///g')
					      sudo mkdir /media/$dirr
					      NTFSLABEL=$(sudo blkid -c /dev/null -t TYPE=ntfs | grep $curline | grep LABEL)
					      if [ $NTFSLABEL ]; then
					      NTFSUUID=$(sudo blkid -c /dev/null -t TYPE=ntfs | grep $curline | cut -d '"' -f 4)
					      else
					      NTFSUUID=$(sudo blkid -c /dev/null -t TYPE=ntfs | grep $curline | cut -d '"' -f 2)
					      fi
					      echo $NTFSUUID #debugging
					      eval "echo UUID=$NTFSUUID	/media/$dirr ntfs-3g      users                        0  0" | sudo tee -a /etc/fstab > /dev/null
					done < /tmp/checkntfs.txt
					echo Done!
				fi
                         rm /tmp/checkntfs.txt /tmp/checkntfs-3g.txt > /dev/null 2>&1;
              elif [ "$choicee" = "$WORD33" ];
                     then
                     sudo rm /etc/fstab_back > /dev/null 2>&1; sudo cp /etc/fstab /etc/fstab_back; cat /etc/fstab_back | sudo sed -e '/^UUID.*ntfs-3g.*/d' > /etc/fstab; sudo rm /etc/fstab_back > /dev/null 2>&1;
              elif [ "$choicee" = "$WORD34" ];
                   then
                   testConnection
                   sudo rm /etc/apt/sources.list_backup > /dev/null 2>&1;
                   sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup
                          /usr/bin/zenity --info --text="$WORD38"
                          testmedibuntu=`wget --tries=1 --timeout=10 http://packages.medibuntu.org/ -O /tmp/testmedibuntumain; cat /tmp/testmedibuntumain | wc -l`
                          testmedibuntuu=`wget --tries=1 --timeout=10 http://mirrors.ucr.ac.cr/medibuntu/ -O /tmp/testmedibuntuu; cat /tmp/testmedibuntuu | wc -l`
                          testmedibuntuuu=`wget --tries=1 --timeout=10 http://mirror.oscc.org.my/medibuntu/ -O /tmp/testmedibuntuuu; cat /tmp/testmedibuntuuu | wc -l`
                          testmedibuntuuuu=`wget --tries=1 --timeout=10 ftp://ftp.leg.uct.ac.za/pub/linux/medibuntu/ -O /tmp/testmedibuntuuuu; cat /tmp/testmedibuntuuuu | wc -l`
                          testgetdeb=`wget --tries=1 --timeout=10 http://archive.getdeb.net/getdeb/ -O /tmp/testgetdeb; cat /tmp/testgetdeb | wc -l`
                          testgetdebb=`wget --tries=1 --timeout=10 http://mirrors.dotsrc.org/getdeb/ -O /tmp/testgetdebb; cat /tmp/testgetdebb | wc -l`
                          if [ $testmedibuntu -gt 0 ]; then
                                mediserv="http://packages.medibuntu.org"
                                medibuntuserver="deb http://packages.medibuntu.org/ lucid free non-free"
                                medibuntuSOURCEserver="deb-src http://packages.medibuntu.org/ lucid free non-free"
                          elif [ $testmedibuntuu -gt 0 ]; then
                                mediserv="http://mirrors.ucr.ac.cr/medibuntu"
                                medibuntuserver="deb http://mirrors.ucr.ac.cr/medibuntu/ lucid free non-free"
                                medibuntuSOURCEserver="deb-src http://mirrors.ucr.ac.cr/medibuntu/ lucid free non-free"
                          elif [ $testmedibuntuuu -gt 0 ]; then
                                mediserv="http://mirror.oscc.org.my/medibuntu"
                                medibuntuserver="deb http://mirror.oscc.org.my/medibuntu/ lucid free non-free"
                                medibuntuSOURCEserver="deb-src http://mirror.oscc.org.my/medibuntu/ lucid free non-free"
                          elif [ $testmedibuntuuuu -gt 0 ]; then
                                mediserv="ftp://ftp.leg.uct.ac.za/pub/linux/medibuntu"
                                medibuntuserver="deb ftp://ftp.leg.uct.ac.za/pub/linux/medibuntu/ lucid free non-free"
                                medibuntuSOURCEserver="deb-src ftp://ftp.leg.uct.ac.za/pub/linux/medibuntu/ lucid free non-free"
                          fi
                          if [ $testgetdeb -gt 0 ]; then
                                getdebserver="deb http://archive.getdeb.net/ubuntu lucid-getdeb apps"
                                getdebSOURCEserver="deb-src http://archive.getdeb.net/ubuntu lucid-getdeb apps"
                          elif [ $testgetdebb -gt 0 ]; then
                                getdebserver="deb http://mirrors.dotsrc.org/getdeb/ubuntu lucid-getdeb apps"
                                getdebSOURCEserver="deb-src http://mirrors.dotsrc.org/getdeb/ubuntu lucid-getdeb apps"
                          fi
                          rm /tmp/testmedibuntumain /tmp/testmedibuntuu /tmp/testmedibuntuuu /tmp/testmedibuntuuuu /tmp/testgetdeb /tmp/testgetdebb > /dev/null 2>&1;
                   
                   cat /etc/apt/sources.list_backup | sed -e '/.*ubuntu\.com\/ubuntu.*/d' > /etc/apt/sources.list; sleep 1; cp /etc/apt/sources.list /etc/apt/sources.list_backup2  #delete the ubuntu default repositories so we don't get double repos
                   sleep 1 | cp /etc/apt/sources.list /etc/apt/sources.list_medibuntu; cat /etc/apt/sources.list_medibuntu | sed -e '/.*medibuntu.*lucid free non-free/d' -e '/.*getdeb.*lucid-getdeb apps/d' > /etc/apt/sources.list; rm /etc/apt/sources.list_medibuntu > /dev/null 2>&1; sleep 1 #delete medibuntu and getdeb repos to make sure we don't get double repos
                   sleep 1; cp /etc/apt/sources.list /etc/apt/sources.list_empty; cat /etc/apt/sources.list_empty | sed '/^$/d' > /etc/apt/sources.list; sleep 1; rm /etc/apt/sources.list_empty > /dev/null 2>&1; #remove empty lines in sources.list
                   ARRAY=( 'deb http://archive.ubuntu.com/ubuntu lucid main restricted universe multiverse' 'deb-src http://archive.ubuntu.com/ubuntu lucid main restricted universe multiverse' 'deb http://archive.ubuntu.com/ubuntu lucid-updates main restricted universe multiverse' 'deb-src http://archive.ubuntu.com/ubuntu lucid-updates main restricted universe multiverse' 'deb http://archive.ubuntu.com/ubuntu lucid-backports main restricted universe multiverse' 'deb-src http://archive.ubuntu.com/ubuntu lucid-backports main restricted universe multiverse' 'deb http://archive.canonical.com/ubuntu lucid partner' 'deb-src http://archive.canonical.com/ubuntu lucid partner' 'deb http://security.ubuntu.com/ubuntu lucid-security main restricted universe multiverse' 'deb-src http://security.ubuntu.com/ubuntu lucid-security main restricted universe multiverse' $medibuntuserver $medibuntuSOURCEserver $getdebserver $getdebSOURCEserver )
                  ELEMENTS=${#ARRAY[@]}

                  for (( i=0;i<$ELEMENTS;i++));
                      do 
                         repos=`cat /etc/apt/sources.list | grep "${ARRAY[${i}]}"`
                         if [ $? -eq 0 ];
                         then
                              echo "${ARRAY[${i}]}" already exists, skipping
                         else
                              echo "${ARRAY[${i}]}" | sudo tee -a /etc/apt/sources.list > /dev/null # add all the repositories which are not in the sources.list file already
                         fi
                      done
                   testConnection
                   rm /etc/apt/sources.list.d/medibuntu.list /etc/apt/sources.list.d/dropbox.list /etc/apt/sources.list.d/getdeb.list > /dev/null 2>&1; #delete medibuntu, dropbox and getdeb repos if they were placed in a different location (not sources.list) because we'll add them anyway - fix for not getting double repos
                   wget -q -O- $mediserv/medibuntu-key.gpg | sudo apt-key add -
                   #sudo apt-get --quiet update && sudo apt-get --yes --quiet --allow-unauthenticated install medibuntu-keyring && sudo apt-get --quiet update
                   sudo apt-key adv --recv-keys --keyserver pgp.mit.edu 46D7E7CF #getdeb key
                   sudo apt-get update
               fi
        done
        IFS=""
        /usr/bin/zenity --info --text="$WORD39"
else
        echo cancel selected
fi

#gui 2
choices=`/usr/bin/zenity --title="$WORD40" --width=520 --height=400 \
                         --text="$WORD41" \
                         --list --column="$WORD10" --column="$WORD42" --column="$WORD43" \
                         --checklist TRUE "GIMP" "$WORD44" TRUE "$WORD45" "$WORD46" TRUE "WINE" "$WORD47"  TRUE "Dock bar" "$WORD48" TRUE "Chromium Browser" "$WORD49" TRUE "$WORD50" "$WORD51" TRUE "Gnome-Do" "$WORD52" TRUE "Guake" "$WORD53" TRUE "VLC" "$WORD54" TRUE "MPlayer" "$WORD54" TRUE "SMPlayer" "$WORD55" TRUE "Thunderbird" "$WORD56" TRUE "$WORD57" "$WORD58" TRUE "Ubuntu-Tweak" "$WORD59" TRUE "Dropbox" "$WORD60" TRUE "Deluge" "$WORD61" TRUE "$WORD62" "$WORD63" TRUE "Skype" "$WORD64" TRUE "Google Chrome" "$WORD65" FALSE "Google Earth" "$WORD66" FALSE "$WORD67" "$WORD68"`

if [ $? -eq 0 ]
then
        IFS="|"
        testConnection
        /usr/bin/zenity --info --text="$WORD69"
        for choice in $choices
        do
              if [ "$choice" = "$WORD57" ];
                   then
                   sudo echo sun-java6-jre shared/accepted-sun-dlj-v1-1 select true | sudo /usr/bin/debconf-set-selections #autoaccept java license
                   sudo apt-get install --yes sun-java6-plugin
                       if [ "i686" = `uname -m` ]; then
                           sudo apt-get -y --force-yes install gstreamer0.10-ffmpeg gstreamer0.10-pitfdll gstreamer0.10-plugins-bad gstreamer0.10-plugins-bad-multiverse gstreamer0.10-plugins-ugly gstreamer0.10-plugins-ugly-multiverse libdvdnav4 libdvdread4 libdvdcss2 libxine1-ffmpeg ffmpeg w32codecs flashplugin-nonfree sun-java6-fonts rar unrar p7zip-full p7zip-rar unace unp ttf-mscorefonts-installer ttf-liberation mencoder
                       else
                           sudo apt-get -y --force-yes install gstreamer0.10-ffmpeg gstreamer0.10-plugins-bad gstreamer0.10-plugins-bad-multiverse gstreamer0.10-plugins-ugly gstreamer0.10-plugins-ugly-multiverse libdvdnav4 libdvdread4 libdvdcss2 libxine1-ffmpeg ffmpeg w64codecs sun-java6-fonts rar unrar p7zip-full p7zip-rar unace unp ttf-mscorefonts-installer ttf-liberation mencoder
                           cd /tmp
                           wget http://download.macromedia.com/pub/labs/flashplayer10/libflashplayer-10.0.45.2.linux-x86_64.so.tar.gz
                           tar xzf libflashplayer-10.0.45.2.linux-x86_64.so.tar.gz
                           sudo mkdir /usr/lib/flashplugin-nonfree/
                           sudo mv libflashplayer.so /usr/lib/flashplugin-nonfree/
                           sudo ln -s /usr/lib/flashplugin-nonfree/libflashplayer.so /usr/lib/mozilla/plugins/libflashplayer.so
                           rm libflashplayer-10.0.45.2.linux-x86_64.so.tar.gz > /dev/null 2>&1;
                      fi
             elif [ "$choice" = "Dock bar" ];
                   then
                        choicesdock=`/usr/bin/zenity --title="$WORD70" --width=450 --height=200 \
                               --text="$WORD71" \
                               --list --column="$WORD10" --column="$WORD42" --column="$WORD43" \
                               --checklist FALSE "Docky" "$WORD72" FALSE "Cairo Dock" "$WORD73" FALSE "Avant Window Navigator" "$WORD74"`
                               if [ $? -eq 0 ];
                                   then
                                   IFSS="|"
                                           for choicedock in $choicesdock
                                           do
                                              if [ "$choicedock" = "Docky" ];
                                                  then
                                                  sudo add-apt-repository ppa:docky-core/ppa
                                                  sudo apt-get update 
                                                  sudo apt-get -y --force-yes install docky
                                              elif [ "$choicedock" = "Cairo Dock" ]; then
                                                  sudo apt-get -y --force-yes install cairo-dock cairo-dock-plug-ins
                                                  sudo apt-get install -f -y 
                                              elif [ "$choicedock" = "Avant Window Navigator" ]; then
                                                  sudo apt-get -y --force-yes install avant-window-navigator awn-applets-c-extras awn-applets-python-extras python-awn-extras
                                              fi
                                           done
                                fi              

             elif [ "$choice" = "Google Chrome" ];
                   then
                        cd /tmp
                           wget http://dl.google.com/linux/direct/google-chrome-unstable_current_${arch}.deb
                           sudo dpkg -i --force-all google-chrome-unstable_current_${arch}.deb
                           sudo apt-get install -f -y
                           rm google-chrome-unstable_current_${arch}.deb > /dev/null 2>&1;
             elif [ "$choice" = "Chromium Browser" ];
                   then
                        cd /tmp
                           sudo apt-get -y --force-yes install chromium-browser chromium-browser-l10n
             elif [ "$choice" = "Skype" ];
                   then
                         sudo apt-get install skype
#                        cd /tmp
#                           wget http://download.skype.com/linux/skype-ubuntu-intrepid_2.1.0.81-1_${arch}.deb
#                           sudo dpkg -i --force-all skype-ubuntu-intrepid_2.1.0.81-1_${arch}.deb
#                           sudo apt-get install -f -y
#                           rm skype-ubuntu-intrepid_2.1.0.81-1_${arch}.deb > /dev/null 2>&1;
             elif [ "$choice" = "$WORD45" ];
                   then
                        sudo apt-get -y --force-yes install pidgin
                      if [ ! -d ~/.purple ]; then
                        echo Pidgin dir does not exist, create it
                        mkdir ~/.purple
                        mkdir ~/.purple/smileys
                        cd ~/.purple
                        wget http://launchpad.net/ubuntustart/trunk/0.4.2/+download/prefs.xml
                      else
                        echo Pidgin dir exists, return
                      fi
                        rm ~/.purple/prefs_backup.xml > /dev/null 2>&1; #in case the user runs the script twice
                        cd ~/.purple/smileys/
                        wget http://launchpad.net/ubuntustart/trunk/0.4.2/+download/pidgin-original-1.9.tgz
                        tar -xvf pidgin-original-1.9.tgz
                        rm pidgin-original-1.9.tgz > /dev/null 2>&1;
                        cp ~/.purple/prefs.xml ~/.purple/prefs_backup.xml
                        cat ~/.purple/prefs_backup.xml | sed -e '/smileys/,/theme/s/Default/Original Smileys 1\.9/g' > ~/.purple/prefs.xml
                        chown -R $ON_USER ~/.purple/smileys/
                        chown -R $ON_USER ~/.purple/prefs_backup.xml
                        chown -R $ON_USER ~/.purple/
             elif [ "$choice" = "$WORD50" ];
                   then
                        sudo add-apt-repository ppa:bisigi/ppa
                        sudo apt-get update
                        sudo apt-get -y --force-yes install bisigi-themes community-themes
             elif [ "$choice" = "Google Earth" ];
                   then
                        sudo echo googleearth shared/accepted-googleearth-eula select true | sudo /usr/bin/debconf-set-selections #autoaccept google earth license
                        if [ "i686" = `uname -m` ]; then
                        sudo apt-get -y --force-yes install googleearth googleearth-data                     
                        
                        else
                        sudo apt-get -y --force-yes install ia32-libs
                        sudo apt-get -y --force-yes install googleearth googleearth-data
                        sudo apt-get install -f -y 
                        fi

             elif [ "$choice" = "$WORD67" ];
                   then
                        sudo apt-get -y --force-yes install build-essential automake make checkinstall dpatch patchutils autotools-dev debhelper quilt fakeroot xutils lintian cmake dh-make libtool autoconf git-core subversion bzr
                        #also needed: pbuilder for deb packages, but removed to to postfix package installation
             elif [ "$choice" = "Dropbox" ];
                   then
                         rm /etc/apt/sources.list.d/dropbox.list #delete the dropbox repo if it's added to a separate file so we don't get double repositories
                         reposs=`cat /etc/apt/sources.list | grep "dropbox"`
                         if [ $? -eq 0 ];
                         then
                              echo Dropbox repository already exists, skipping repository add
                              sudo apt-get update
                              sudo apt-get -y --force-yes install nautilus-dropbox
                         else
                              echo "deb http://linux.dropbox.com/ubuntu lucid main" | sudo tee -a /etc/apt/sources.list > /dev/null
                              echo "deb-src http://linux.dropbox.com/ubuntu lucid main" | sudo tee -a /etc/apt/sources.list > /dev/null
                              sudo apt-key adv --recv-keys --keyserver pgp.mit.edu 3565780E #dropbox key
                              sudo apt-get update
                              sudo apt-get -y --force-yes install nautilus-dropbox
                         fi
              elif [ "$choice" = "$WORD62" ];
                   then
                        sudo apt-get -y --force-yes install compizconfig-settings-manager compiz-fusion-plugins-extra

              else
                        choiceLOW=`echo $choice | tr '[:upper:]' '[:lower:]'`
                        sudo apt-get -y --force-yes install $choiceLOW
                        sudo apt-get install -f -y 
            fi
       done
#cleaning up
       sudo apt-get clean
       sudo apt-get autoclean
#notices
       if [[ "$choicee" = "$WORD24" || "$choicee" = "$WORD28" || "$choicee" = "$WORD25" || "$choicee" = "$WORD29" ]]; then
       /usr/bin/zenity --info --text="$WORD75 http://www.webupd8.org"
       else
       /usr/bin/zenity --info --text="$WORD76 http://www.webupd8.org"
       IFS=""
       fi
       rm /tmp/testinternet > /dev/null 2>&1;
else
       rm /tmp/testinternet > /dev/null 2>&1;
       echo cancel selected
       exit
fi


#changelog

#0.4.9.5
#new Chrome download link
#install skype from the Ubuntu partner repo

#0.4.9.4
#added Danish translation
#updated Estonian translation

#0.4.9.3
#google changed the URL for Chrome so I added the new one
#download pidgin smileys from a different location as it seems the server is overloaded

#0.4.9.2
#fixed some bugs in the English and Traditional Chinese translation
#added Urdu language

#0.4.9.1
#added vietnamese language

#0.4.9
#bug-fix release

#0.4.8.9
#fixed double repository issue

#0.4.8.8
#added traditional chinese language

#0.4.8.7
#added swedish language

#0.4.8.6:
#added arabic translation

#0.4.8.5:
#removed pbuilder from development tools due to postfix package dependency which requires the user to interact with the terminal
#added slovenian and romanian translations

#0.4.8.4
#fixed Asturian language not working

#0.4.8.3
#fixed pidgin smileys bug

#0.4.8.2
#added basha indonesia, asturian languages, updated italian, dutch, slovenian, czech

#0.4.8.1
#added brazilian portuguese and catalan languages
#added estonian

#0.4.8
#added Docky, Cairo Dock and AWN in a separate dialog
#made Google Earth installation autoaccept the license so the user doesn't have to interact with the terminal
#multiple language support; current languages: Czech, Spanish, French, German, Slovak, Italian, Polish, Japanese, Dutch, Portuguese (PT), Malaysian, Galician, Korean
#changed the way the current logged in user is detected; this should hopefully fix multiple accounts issues

#0.4.7
#extra themes (community themes and bisigi themes)
#google earth

#0.4.6
#bugs bugs bugs fixed
#added extra compiz plugins to install
#added getdeb mirror
#code optimizations

#0.4.5
#Added reset options for the tweaks
#Changed the way day of the week from Sunday to Monday works - it now asks the user to enter his locale.

#0.4.4
#fixed lots of minor bugs, the script is now more stable

#0.4.3
#replace karmic dropbox repository with lucid
#code cleanup


#0.4.2.2
#removed devtools package from development packages options due to this package requesting user interaction with the terminal
#fix GPG keys import for medibuntu and getdeb

#0.4.2.1
#fixed Pidgin installation not working
#added one more Medibuntu mirror
#clean empty lines in sources.list
#remove 15s sleep for when testing medibuntu mirrors

#v0.4.2
#added Change Gnome Calendar first day of the week from Sunday to Monday tweak.
#check if the user selects an options which requires he logs out and then logs back in and if so, notify him.
#lots of fixes, especially to automatically mount NTFS drives feature which now add drives by UUID instead of name
#clean up when done
#internet connection check
#fix double repositories in some cases
#added 2 medibuntu mirrors in case medibuntu main server is down, will check which one is working and add it to sources.list

#v0.4.1
#added smplayer
#integrated Mongi Gazelle's sharp fonts script: http://www.webupd8.org/2009/09/ubuntu-debian-script-to-install-sharp.html
#also from Mongi Gazelle's script: incorporated the synaptic, apt-get, etc. check and if those processes are running, close the script and ask the user to close them before running the script
#added guake
#included original protocol smileys with Pidgin installation (from http://files.andreineculau.com/projects/pidgin/original-smileys/)
#install deluge
#automatically mount NTFS drives on startup

#v0.4
#added Skype 32bit and 64bit download & install
#sudo check: the script exists if it is not run as sudo
#install compizconfig-settings-manager
#show dialog when going from step 1 to step 2 and show "Done" dialog when all the packages in step 2 have been installed
#fixed 'disable GDM login sound'

#v0.3
#added gnome-do
#Remove drive icons from desktop gconf tweak
#fix Google Chrome repository slowness for "apt-get update"
#some other fixes

#v0.2:
#added autoaccept for the java license when installing the java plugin
#added dropbox repository and installation
#added disable GDM login user list
#added build-essential, subversion, git, etc
